package com.ruoyi.wgjlcData.service.impl;

import com.deepoove.poi.data.PictureRenderData;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.*;
import com.ruoyi.task.domain.entity.DataTaskEntity;
import com.ruoyi.task.service.IDataTaskService;
import com.ruoyi.wgjlcData.domain.pad.WgjlcTaskReqDTO;
import com.ruoyi.wgjlcData.domain.pad.WgjlcTaskRespDTO;
import com.ruoyi.wgjlcData.domain.pad.WgjlcTreeDataItemDto;
import com.ruoyi.wgjlcData.domain.plat.*;
import com.ruoyi.wgjlcData.domain.report.WgjlcReportData;
import com.ruoyi.wgjlcData.domain.vo.*;
import com.ruoyi.wgjlcData.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;


/**
 * 单轨吊面温度数据Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-28
 */
@Service
public class DataWgjlcServiceImpl implements IDataWgjlcService
{

    @Autowired
    private IDataTaskService dataTaskService;

    @Autowired
    private IDataWgjlcChwqdService dataWgjlcChwqdService;

    @Autowired
    private IDataWgjlcCzjService dataWgjlcCzjService;

    @Autowired
    private IDataWgjlcCzlService dataWgjlcCzlService;

    @Autowired
    private IDataWgjlcPdtchzhdService dataWgjlcPdtchzhdService;

    @Autowired
    private IDataWgjlcPpnlService dataWgjlcPpnlService;

    @Autowired
    private IDataWgjlcShshlService dataWgjlcShshlService;

    @Autowired
    private IDataWgjlcSuduService dataWgjlcSuduService;

    @Autowired
    private IDataWgjlcTblService dataWgjlcTblService;

    @Autowired
    private IDataWgjlcWdbhService dataWgjlcWdbhService;

    @Autowired
    private IDataWgjlcWeiqiService dataWgjlcWeiqiService;

    @Autowired
    private IDataWgjlcYandujiService dataWgjlcYandujiService;

    @Autowired
    private IDataWgjlcYlbhService dataWgjlcYlbhService;

    @Autowired
    private IDataWgjlcZdjzdlService dataWgjlcZdjzdlService;

    @Autowired
    private IDataWgjlcZdqylService dataWgjlcZdqylService;

    @Autowired
    private IDataWgjlcZhdjlgpsService dataWgjlcZhdjlgpsService;

    @Autowired
    private IDataWgjlcZhmhxhService dataWgjlcZhmhxhService;

    @Autowired
    private IDataWgjlcZshhjshService dataWgjlcZshhjshService;

    @Autowired
    private IDataWgjlcZxtgbjService dataWgjlcZxtgbjService;

    /**
     * 详情数据
     *
     * @param dataTaskId
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @Override
    public WgjlcTaskReqDTO getDetailWgjlc(Long dataTaskId) throws ExecutionException, InterruptedException {
        long startTime = System.currentTimeMillis();
        //测试数据基本信息
        Future<DataTaskEntity> taskFuture = dataTaskService.selectDataTask(dataTaskId);
        //常温启动测试数据
        Future<List<DataWgjlcChwqd>> chwqdListFuture = dataWgjlcChwqdService.selectDataWgjlcChwqdByDataTaskId(dataTaskId);
        //最大操纵角测试项
        Future<List<DataWgjlcCzj>> czjListFuture = dataWgjlcCzjService.selectDataWgjlcChwqdByDataTaskId(dataTaskId);
        //最大操纵力测试数据
        Future<List<DataWgjlcCzl>> czlListFuture = dataWgjlcCzlService.selectDataWgjlcCzjByDataTaskId(dataTaskId);
        //坡道停车制动测试数据
        Future<List<DataWgjlcPdtchzhd>> pdtchzhdListFuture = dataWgjlcPdtchzhdService.selectDataWgjlcPdtchzhdByDataTaskId(dataTaskId);
        //爬坡能力测试数据
        Future<List<DataWgjlcPpnl>> ppnlListFuture = dataWgjlcPpnlService.selectDataWgjlcPpnlByDataTaskId(dataTaskId);
        //手刹力测试数据
        Future<List<DataWgjlcShshl>> shshlListFuture = dataWgjlcShshlService.selectDataWgjlcShshlByDataTaskId(dataTaskId);
        //运行速度数据
        Future<List<DataWgjlcSudu>> suduListFuture = dataWgjlcSuduService.selectDataWgjlcSuduByDataTaskId(dataTaskId);
        //踏板力数据
        Future<List<DataWgjlcTbl>> tblListFuture = dataWgjlcTblService.selectDataWgjlcTblByDataTaskId(dataTaskId);
        //温度保护数据
        Future<List<DataWgjlcWdbh>> wdbhListFuture = dataWgjlcWdbhService.selectDataWgjlcWdbhByDataTaskId(dataTaskId);
        //尾气数据
        Future<List<DataWgjlcWeiqi>> weiqiListFuture = dataWgjlcWeiqiService.selectDataWgjlcWeiqiByDataTaskId(dataTaskId);
        //烟度计数据
        Future<List<DataWgjlcYanduji>> yandujiListFuture = dataWgjlcYandujiService.selectDataWgjlcYandujiByDataTaskId(dataTaskId);
        //压力保护数据
        Future<List<DataWgjlcYlbh>> ylbhListFuture = dataWgjlcYlbhService.selectDataWgjlcYlbhByDataTaskId(dataTaskId);
        //最大静制动力数据
        Future<List<DataWgjlcZdjzdl>> zdjzdlListFuture = dataWgjlcZdjzdlService.selectDataWgjlcZdjzdlByDataTaskId(dataTaskId);
        //最大牵引力数据
        Future<List<DataWgjlcZdqyl>> zdqylListFuture = dataWgjlcZdqylService.selectDataWgjlcZdqylByDataTaskId(dataTaskId);
        //制动距离数据
        Future<List<DataWgjlcZhdjlgps>> zhdjlgpsListFuture = dataWgjlcZhdjlgpsService.selectDataWgjlcZhdjlgpsByDataTaskId(dataTaskId);
        //照明及信号数据
        Future<List<DataWgjlcZhmhxh>> zhmhxhListFuture = dataWgjlcZhmhxhService.selectDataWgjlcZhmhxhByDataTaskId(dataTaskId);
        //噪声和警声数据
        Future<List<DataWgjlcZshhjsh>> zshhjshListFuture = dataWgjlcZshhjshService.selectDataWgjlcZshhjshByDataTaskId(dataTaskId);
        //最小通过半径数据
        Future<List<DataWgjlcZxtgbj>> zxtgbjListFuture = dataWgjlcZxtgbjService.selectDataWgjlcZxtgbjByDataTaskId(dataTaskId);
        //添加到集合对象中
        List<Future<?>> futureList = new ArrayList<>();
        futureList.add(taskFuture);
        futureList.add(chwqdListFuture);
        futureList.add(czjListFuture);
        futureList.add(czlListFuture);
        futureList.add(pdtchzhdListFuture);
        futureList.add(ppnlListFuture);
        futureList.add(shshlListFuture);
        futureList.add(suduListFuture);
        futureList.add(tblListFuture);
        futureList.add(wdbhListFuture);
        futureList.add(weiqiListFuture);
        futureList.add(yandujiListFuture);
        futureList.add(ylbhListFuture);
        futureList.add(zdjzdlListFuture);
        futureList.add(zdqylListFuture);
        futureList.add(zhdjlgpsListFuture);
        futureList.add(zhmhxhListFuture);
        futureList.add(zshhjshListFuture);
        futureList.add(zxtgbjListFuture);
        // 从future提取所有数据
        WgjlcTaskRespDTO wgjlcTaskRespDTO = new WgjlcTaskRespDTO();
        for (Future<?> future : futureList) {
            while (true) {
                if (taskFuture.isDone() && !taskFuture.isCancelled()) {
                    // 获取结果
                    Object resultObject = future.get();
                    // 任务数据
                    if (resultObject instanceof DataTaskEntity) {
                        wgjlcTaskRespDTO.setDataTaskEntity((DataTaskEntity) resultObject);
                    }
                    if (resultObject instanceof List) {
                        List<Object> resultList = (List<Object>) resultObject;
                        if (!resultList.isEmpty()) {
                            Object item = resultList.get(0);
                            //测试任务类型获取数据
                            if (item instanceof DataWgjlcChwqd) {
                                wgjlcTaskRespDTO.setChwqdEntityList(ListUtils.castList(resultList, DataWgjlcChwqd.class));
                            }
                            if (item instanceof DataWgjlcCzj) {
                                wgjlcTaskRespDTO.setCzjEntityList(ListUtils.castList(resultList, DataWgjlcCzj.class));
                            }
                            if (item instanceof DataWgjlcCzl) {
                                wgjlcTaskRespDTO.setCzlEntityList(ListUtils.castList(resultList, DataWgjlcCzl.class));
                            }
                            if (item instanceof DataWgjlcPdtchzhd) {
                                wgjlcTaskRespDTO.setPdtchzhdEntityList(ListUtils.castList(resultList, DataWgjlcPdtchzhd.class));
                            }
                            if (item instanceof DataWgjlcPpnl) {
                                wgjlcTaskRespDTO.setPpnlEntityList(ListUtils.castList(resultList, DataWgjlcPpnl.class));
                            }
                            if (item instanceof DataWgjlcShshl) {
                                wgjlcTaskRespDTO.setShshlEntityList(ListUtils.castList(resultList, DataWgjlcShshl.class));
                            }
                            if (item instanceof DataWgjlcSudu) {
                                wgjlcTaskRespDTO.setSuDuEntityList(ListUtils.castList(resultList, DataWgjlcSudu.class));
                            }
                            if (item instanceof DataWgjlcTbl) {
                                wgjlcTaskRespDTO.setTblEntityList(ListUtils.castList(resultList, DataWgjlcTbl.class));
                            }
                            if (item instanceof DataWgjlcWdbh) {
                                wgjlcTaskRespDTO.setWdbhEntityList(ListUtils.castList(resultList, DataWgjlcWdbh.class));
                            }
                            if (item instanceof DataWgjlcWeiqi) {
                                wgjlcTaskRespDTO.setWeiQiEntityList(ListUtils.castList(resultList, DataWgjlcWeiqi.class));
                            }
                            if (item instanceof DataWgjlcYanduji) {
                                wgjlcTaskRespDTO.setYanDuJiEntityList(ListUtils.castList(resultList, DataWgjlcYanduji.class));
                            }
                            if (item instanceof DataWgjlcYlbh) {
                                wgjlcTaskRespDTO.setYlbhEntityList(ListUtils.castList(resultList, DataWgjlcYlbh.class));
                            }
                            if (item instanceof DataWgjlcZdjzdl) {
                                wgjlcTaskRespDTO.setZdjzdlEntityList(ListUtils.castList(resultList, DataWgjlcZdjzdl.class));
                            }
                            if (item instanceof DataWgjlcZdqyl) {
                                wgjlcTaskRespDTO.setZdqylEntityList(ListUtils.castList(resultList, DataWgjlcZdqyl.class));
                            }
                            if (item instanceof DataWgjlcZhdjlgps) {
                                wgjlcTaskRespDTO.setZhdjlGpsEntityList(ListUtils.castList(resultList, DataWgjlcZhdjlgps.class));
                            }
                            if (item instanceof DataWgjlcZhmhxh) {
                                wgjlcTaskRespDTO.setZhmhxhEntityList(ListUtils.castList(resultList, DataWgjlcZhmhxh.class));
                            }
                            if (item instanceof DataWgjlcZshhjsh) {
                                wgjlcTaskRespDTO.setZshhjshEntityList(ListUtils.castList(resultList, DataWgjlcZshhjsh.class));
                            }
                            if (item instanceof DataWgjlcZxtgbj) {
                                wgjlcTaskRespDTO.setZxtgbjEntityList(ListUtils.castList(resultList, DataWgjlcZxtgbj.class));
                            }
                        }
                    }
                    break;
                } else {
                    // 轮询查询结果
                    Thread.sleep(10);
                }
            }
        }
        //目录结构拼接
        List<WgjlcTreeDataItemDto> treeDataList = new ArrayList<>();
        //踏板力数据
        if (null != wgjlcTaskRespDTO.getTblEntityList() && !wgjlcTaskRespDTO.getTblEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("tblEntityList");
            wgjlcTaskRespDTO.getTblEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("tblEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //手刹力测试数据
        if (null != wgjlcTaskRespDTO.getShshlEntityList() && !wgjlcTaskRespDTO.getShshlEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("shshlEntityList");
            wgjlcTaskRespDTO.getShshlEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("shshlEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //最大操纵力测试数据
        if (null != wgjlcTaskRespDTO.getCzlEntityList() && !wgjlcTaskRespDTO.getCzlEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("czlEntityList");
            wgjlcTaskRespDTO.getCzlEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("czlEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //最大操纵角测试项
        if (null != wgjlcTaskRespDTO.getCzjEntityList() && !wgjlcTaskRespDTO.getCzjEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("czjEntityList");
            wgjlcTaskRespDTO.getCzjEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("czjEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //最小通过半径数据
        if (null != wgjlcTaskRespDTO.getZxtgbjEntityList() && !wgjlcTaskRespDTO.getZxtgbjEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zxtgbjEntityList");
            wgjlcTaskRespDTO.getZxtgbjEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zxtgbjEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //运行速度数据
        if (null != wgjlcTaskRespDTO.getSuDuEntityList() && !wgjlcTaskRespDTO.getSuDuEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("suDuEntityList");
            wgjlcTaskRespDTO.getSuDuEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("suDuEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //最大牵引力数据
        if (null != wgjlcTaskRespDTO.getZdqylEntityList() && !wgjlcTaskRespDTO.getZdqylEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zdqylEntityList");
            wgjlcTaskRespDTO.getZdqylEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zdqylEntityList");
            treeDataList.add(treeDataItemDto);
        }
        // 爬坡能力测试数据
        if (null != wgjlcTaskRespDTO.getPpnlEntityList() && !wgjlcTaskRespDTO.getPpnlEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("ppnlEntityList");
            wgjlcTaskRespDTO.getPpnlEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("ppnlEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //常温启动测试数据
        if (null != wgjlcTaskRespDTO.getChwqdEntityList() && !wgjlcTaskRespDTO.getChwqdEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("chwqdEntityList");
            wgjlcTaskRespDTO.getChwqdEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("chwqdEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //压力保护数据
        if (null != wgjlcTaskRespDTO.getYlbhEntityList() && !wgjlcTaskRespDTO.getYlbhEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("ylbhEntityList");
            wgjlcTaskRespDTO.getYlbhEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("ylbhEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //温度保护数据
        if (null != wgjlcTaskRespDTO.getWdbhEntityList() && !wgjlcTaskRespDTO.getWdbhEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("wdbhEntityList");
            wgjlcTaskRespDTO.getWdbhEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("wdbhEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //最大静制动力数据
        if (null != wgjlcTaskRespDTO.getZdjzdlEntityList() && !wgjlcTaskRespDTO.getZdjzdlEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zdjzdlEntityList");
            wgjlcTaskRespDTO.getZdjzdlEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zdjzdlEntityList");
            treeDataList.add(treeDataItemDto);
        }
        // 坡道停车制动测试数据
        if (null != wgjlcTaskRespDTO.getPdtchzhdEntityList() && !wgjlcTaskRespDTO.getPdtchzhdEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("pdtchzhdEntityList");
            wgjlcTaskRespDTO.getPdtchzhdEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("pdtchzhdEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //制动距离数据
        if (null != wgjlcTaskRespDTO.getZhdjlGpsEntityList() && !wgjlcTaskRespDTO.getZhdjlGpsEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zhdjlGpsEntityList");
            wgjlcTaskRespDTO.getZhdjlGpsEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zhdjlGpsEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //照明及信号数据
        if (null != wgjlcTaskRespDTO.getZhmhxhEntityList() && !wgjlcTaskRespDTO.getZhmhxhEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zhmhxhEntityList");
            wgjlcTaskRespDTO.getZhmhxhEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zhmhxhEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //噪声和警声数据
        if (null != wgjlcTaskRespDTO.getZshhjshEntityList() && !wgjlcTaskRespDTO.getZshhjshEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zshhjshEntityList");
            wgjlcTaskRespDTO.getZshhjshEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("zshhjshEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //尾气数据
        if (null != wgjlcTaskRespDTO.getWeiQiEntityList() && !wgjlcTaskRespDTO.getWeiQiEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("weiQiEntityList");
            wgjlcTaskRespDTO.getWeiQiEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("weiQiEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //烟度计数据
        if (null != wgjlcTaskRespDTO.getYanDuJiEntityList() && !wgjlcTaskRespDTO.getYanDuJiEntityList().isEmpty()) {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("yanDuJiEntityList");
            wgjlcTaskRespDTO.getYanDuJiEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new WgjlcTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            WgjlcTreeDataItemDto treeDataItemDto = new WgjlcTreeDataItemDto("yanDuJiEntityList");
            treeDataList.add(treeDataItemDto);
        }
        wgjlcTaskRespDTO.setWgjlcTreeDataList(treeDataList);
        System.out.printf("任务ID为 %d 的“无轨胶轮车测试任务”查询耗时 %d。", dataTaskId, (System.currentTimeMillis() - startTime));
        return wgjlcTaskRespDTO;
    }


    /**
     * 删除单轨吊数据，变更数据状态为2
     *
     * @param dataTaskId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delAllWgjlcData(Long dataTaskId) {
        //测试数据基本信息
        //变更任务状态
        try {
            Long[] dataTaskIds = new Long[] {dataTaskId};
            dataTaskService.deleteDataTaskByDataTaskIds(dataTaskIds, "01A");
            //常温启动测试数据
            dataWgjlcChwqdService.updateDataWgjlcChwqdByDataTaskId(dataTaskId);
            //最大操纵角测试项
            dataWgjlcCzjService.updateDataWgjlcCzjByDataTaskId(dataTaskId);
            //最大操纵力测试数据
            dataWgjlcCzlService.updateDataWgjlcCzlByDataTaskId(dataTaskId);
            //坡道停车制动测试数据
            dataWgjlcPdtchzhdService.updateDataWgjlcPdtchzhdByDataTaskId(dataTaskId);
            //爬坡能力测试数据
            dataWgjlcPpnlService.updateDataWgjlcPpnlByDataTaskId(dataTaskId);
            //手刹力测试数据
            dataWgjlcShshlService.updateDataWgjlcShshlByDataTaskId(dataTaskId);
            //运行速度数据
            dataWgjlcSuduService.updateDataWgjlcSuduByDataTaskId(dataTaskId);
            //踏板力数据
            dataWgjlcTblService.updateDataWgjlcTblByDataTaskId(dataTaskId);
            //温度保护数据
            dataWgjlcWdbhService.updateDataWgjlcWdbhByDataTaskId(dataTaskId);
            //尾气数据
            dataWgjlcWeiqiService.updateDataWgjlcWeiqiByDataTaskId(dataTaskId);
            //烟度计数据
            dataWgjlcYandujiService.updateDataWgjlcYandujiByDataTaskId(dataTaskId);
            //压力保护数据
            dataWgjlcYlbhService.updateDataWgjlcYlbhByDataTaskId(dataTaskId);
            //最大静制动力数据
            dataWgjlcZdjzdlService.updateDataWgjlcZdjzdlByDataTaskId(dataTaskId);
            //最大牵引力数据
            dataWgjlcZdqylService.updateDataWgjlcZdqylByDataTaskId(dataTaskId);
            //制动距离数据
            dataWgjlcZhdjlgpsService.updateDataWgjlcZhdjlgpsByDataTaskId(dataTaskId);
            //照明及信号数据
            dataWgjlcZhmhxhService.updateDataWgjlcZhmhxhByDataTaskId(dataTaskId);
            //噪声和警声数据
            dataWgjlcZshhjshService.updateDataWgjlcZshhjshByDataTaskId(dataTaskId);
            //最小通过半径数据
            dataWgjlcZxtgbjService.updateDataWgjlcZxtgbjByDataTaskId(dataTaskId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 1;
    }

    /**
     * 导入报告到无轨胶轮车
     *
     * @param data
     */
    @Override
    public String dataWgjlcImportReport(WgjlcReportData data) {
        // 报告模板名称
        String template = data.getTempId();
        //测试任务信息
        DataTaskEntity dataTaskEntity = dataTaskService.selectDataTaskByDataTaskId(data.getDataTaskEntity().getDataTaskId());
        data.setDataTaskEntity(dataTaskEntity);
        //获取生成的工况图并转换png格式
        String rootPath = RuoYiConfig.getProfile() + RuoYiConfig.getChartPath() + "/";
        //导入报告中
        Map<String, Object> params = new HashMap<>();
        // 大曲线图的长宽
        int picW = 450;
        int picH = 250;
        // 小曲线图的长款
        int picSW = 280;
        int picSH = 156;
        //基本检测信息
        if(null != data.getDataTaskEntity()) {
            params.put("受检单位", data.getDataTaskEntity().getShjdw());
            params.put("设备名称", data.getDataTaskEntity().getShbbh());
            params.put("主检姓名", data.getDataTaskEntity().getZhjxm());
            params.put("测试人员", data.getDataTaskEntity().getCshry());
            params.put("检测日期", DateUtils.dateTime(data.getDataTaskEntity().getTaskCreateTime()));
        }
        //胶轮车参数
        List<Map<String, Object>> tblList = new ArrayList<>();
        List<Map<String, Object>> shshlList = new ArrayList<>();
        List<Map<String, Object>> czlList = new ArrayList<>();
        List<Map<String, Object>> czjList = new ArrayList<>();
        List<Map<String, Object>> qylList = new ArrayList<>();
        List<Map<String, Object>> ppnlList = new ArrayList<>();
        List<Map<String, Object>> chwqdList = new ArrayList<>();
        List<Map<String, Object>> ylbhList = new ArrayList<>();
        List<Map<String, Object>> wdbhList = new ArrayList<>();
        List<Map<String, Object>> zdjzdlList = new ArrayList<>();
        List<Map<String, Object>> weiqiList = new ArrayList<>();
        List<Map<String, Object>> yanduList = new ArrayList<>();
        if(null != data.getTblEntityList() && !data.getTblEntityList().isEmpty()) {
            //踏板力参数
            DataWgjlcTbl dataWgjlcTbl = data.getTblEntityList().get(0);
            if(null != dataWgjlcTbl.getTestOneDataList() && !dataWgjlcTbl.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcTbl.getTestOneDataList();
                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> tblMap = new HashMap<>();
                    tblMap.put("序号", i + 1);
                    tblMap.put("踏板力", tblOneData.get(i).getDataVel());
                    tblList.add(tblMap);
                    }
            }
        }
        //手刹力参数
        if(null != data.getShshlEntityList() && !data.getShshlEntityList().isEmpty()) {
            DataWgjlcShshl dataWgjlcShshl = data.getShshlEntityList().get(0);
            if(null != dataWgjlcShshl.getTestOneDataList() && !dataWgjlcShshl.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcShshl.getTestOneDataList();

                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> shshlMap = new HashMap<>();
                    shshlMap.put("序号", i + 1);
                    shshlMap.put("手刹力", tblOneData.get(i).getDataVel());
                    shshlList.add(shshlMap);
                }
            }
        }
        //操纵力参数
        if(null != data.getCzlEntityList() && !data.getCzlEntityList().isEmpty()) {
            DataWgjlcCzl dataWgjlcCzl = data.getCzlEntityList().get(0);
            if(null != dataWgjlcCzl.getTestOneDataList() && !dataWgjlcCzl.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcCzl.getTestOneDataList();

                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> czlMap = new HashMap<>();
                    czlMap.put("序号", i + 1);
                    czlMap.put("最大操纵力", tblOneData.get(i).getDataVel());
                    czlList.add(czlMap);
                }
            }
        }
        //操纵角参数
        if(null != data.getCzjEntityList() && !data.getCzjEntityList().isEmpty()) {
            DataWgjlcCzj dataWgjlcCzj = data.getCzjEntityList().get(0);
            if(null != dataWgjlcCzj.getTestOneDataList() && !dataWgjlcCzj.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcCzj.getTestOneDataList();

                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> czjMap = new HashMap<>();
                    czjMap.put("序号", i + 1);
                    czjMap.put("最大操纵角", tblOneData.get(i).getDataVel());
                    czjList.add(czjMap);
                }
            }
        }
        //最小通过半径参数
        if (null != data.getZxtgbjEntityList() && !data.getZxtgbjEntityList().isEmpty()) {
            params.put("最小通过半径", data.getZxtgbjEntityList().get(0).getZxtgbjVel());
            String zxtgbjImg = System.currentTimeMillis() + "-最小通过半径GPS图.png";
            if(StringUtils.isNotEmpty(data.getZxtgbjEntityList().get(0).getZxtgbjSvg())) {
                boolean res = ProcessPictureUtils.convertToPng(data.getZxtgbjEntityList().get(0).getZxtgbjSvg(), rootPath + data.getDataTaskEntity().getDataTaskId() + "/" + zxtgbjImg);
                String resString = res ? "成功" : "失败";
                System.out.println("最小通过半径图导入:" + resString);
            }
            params.put("最小通过半径曲线", new PictureRenderData(picW, picH, rootPath + data.getDataTaskEntity().getDataTaskId() + "/" +zxtgbjImg));
        }
        //运行速度参数
        if (null != data.getSuDuEntityList() && !data.getSuDuEntityList().isEmpty()) {
            //获取各档位参数
            DataWgjlcSudu dataWgjlcSudu = data.getSuDuEntityList().get(0);
            if(null != dataWgjlcSudu.getTestSuDuList() && !dataWgjlcSudu.getTestSuDuList().isEmpty()) {
                List<TestSuDu> testSuduList = dataWgjlcSudu.getTestSuDuList();
                for(int i = 0 ; i < testSuduList.size(); i++) {
                    params.put(testSuduList.get(i).getDw() + "最大速度", testSuduList.get(i).getZdsdVel());
                    String dwImg = System.currentTimeMillis() + "-" + testSuduList.get(i).getDw() + "速度曲线图.png";
                    if(StringUtils.isNotEmpty(testSuduList.get(i).getDwSvg())) {
                        boolean res = ProcessPictureUtils.convertToPng(testSuduList.get(i).getDwSvg(), rootPath + data.getDataTaskEntity().getDataTaskId() + "/" + dwImg);
                        String resString = res ? "成功" : "失败";
                        System.out.println(testSuduList.get(i).getDw() + "速度曲线图导入:" + resString);
                    }
                    params.put(testSuduList.get(i).getDw() + "速度曲线图", new PictureRenderData(picSW, picSH, rootPath + data.getDataTaskEntity().getDataTaskId() + "/" +dwImg));
                }
            }
        }
        //最大牵引力参数
        if(null != data.getZdqylEntityList() && !data.getZdqylEntityList().isEmpty()) {
            DataWgjlcZdqyl dataWgjlcZdqyl = data.getZdqylEntityList().get(0);
            if(null != dataWgjlcZdqyl.getTestOneDataList() && !dataWgjlcZdqyl.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcZdqyl.getTestOneDataList();
                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> qylMap = new HashMap<>();
                    qylMap.put("序号", i + 1);
                    qylMap.put("最大牵引力", tblOneData.get(i).getDataVel());
                    qylList.add(qylMap);
                }
            }
        }
        //爬坡能力参数
        if(null != data.getPpnlEntityList() && !data.getPpnlEntityList().isEmpty()) {
            DataWgjlcPpnl dataWgjlcPpnl = data.getPpnlEntityList().get(0);
            if(null != dataWgjlcPpnl.getTestOneDataList() && !dataWgjlcPpnl.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcPpnl.getTestOneDataList();

                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> ppnlMap = new HashMap<>();
                    ppnlMap.put("序号", i + 1);
                    ppnlMap.put("坡道角度", tblOneData.get(i).getDataVel());
                    ppnlList.add(ppnlMap);
                }
            }
        }
        //常温启动性能参数
        if(null != data.getChwqdEntityList() && !data.getChwqdEntityList().isEmpty()) {
            DataWgjlcChwqd dataWgjlcChwqd = data.getChwqdEntityList().get(0);
            if(null != dataWgjlcChwqd.getTestChwqdList() && !dataWgjlcChwqd.getTestChwqdList().isEmpty()) {
                List<TestChwqd> testChwqdList = dataWgjlcChwqd.getTestChwqdList();
                for(int i = 0 ; i < testChwqdList.size(); i++) {
                    Map<String, Object> chwqdMap = new HashMap<>();
                    chwqdMap.put("序号", i + 1);
                    chwqdMap.put("启动时间", testChwqdList.get(i).getQdshjVel());
                    chwqdList.add(chwqdMap);
                }
            }
        }
        //压力保护参数
        if(null != data.getYlbhEntityList() && !data.getYlbhEntityList().isEmpty()) {
            DataWgjlcYlbh dataWgjlcYlbh = data.getYlbhEntityList().get(0);
            if(null != dataWgjlcYlbh.getTestOneDataList() && !dataWgjlcYlbh.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcYlbh.getTestOneDataList();
                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> ylbhMap = new HashMap<>();
                    ylbhMap.put("序号", i + 1);
                    ylbhMap.put("压力", tblOneData.get(i).getDataVel());
                    ylbhList.add(ylbhMap);
                }
            }
        }
        //温度保护参数
        if(null != data.getWdbhEntityList() && !data.getWdbhEntityList().isEmpty()) {
            DataWgjlcWdbh dataWgjlcWdbh = data.getWdbhEntityList().get(0);
            if(null != dataWgjlcWdbh.getTestOneDataList() && !dataWgjlcWdbh.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcWdbh.getTestOneDataList();
                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> wdbhMap = new HashMap<>();
                    wdbhMap.put("序号", i + 1);
                    wdbhMap.put("温度", tblOneData.get(i).getDataVel());
                    wdbhList.add(wdbhMap);
                }
            }
        }
        //最大静制动力参数
        if(null != data.getZdjzdlEntityList() && !data.getZdjzdlEntityList().isEmpty()) {
            DataWgjlcZdjzdl dataWgjlcZdjzdl = data.getZdjzdlEntityList().get(0);
            if(null != dataWgjlcZdjzdl.getTestOneDataList() && !dataWgjlcZdjzdl.getTestOneDataList().isEmpty()) {
                List<TestOneData> tblOneData = dataWgjlcZdjzdl.getTestOneDataList();
                for(int i = 0 ; i < tblOneData.size(); i++) {
                    Map<String, Object> zdjzdlMap = new HashMap<>();
                    zdjzdlMap.put("序号", i + 1);
                    zdjzdlMap.put("最大静制动力", tblOneData.get(i).getDataVel());
                    zdjzdlList.add(zdjzdlMap);
                }
            }
        }
        //坡道停车制动参数
        if(null != data.getPdtchzhdEntityList() && !data.getPdtchzhdEntityList().isEmpty()) {
            List<DataWgjlcPdtchzhd> dataWgjlcPdtchzhds = data.getPdtchzhdEntityList();
            params.put("额定载荷", dataWgjlcPdtchzhds.get(0).getEdzh());
            params.put("测试载荷", dataWgjlcPdtchzhds.get(0).getCshzh());
            params.put("停车是否稳定", dataWgjlcPdtchzhds.get(0).getHasWd().isEmpty() ? "--" : dataWgjlcPdtchzhds.get(0).getHasWd().equals("0") ? "稳定" : "不稳定");
            params.put("停车是否位移", dataWgjlcPdtchzhds.get(0).getHasWy().isEmpty() ? "--" : dataWgjlcPdtchzhds.get(0).getHasWy().equals("0") ? "否" : "产生");
        }
        //制动距离参数
        if (null != data.getZhdjlGpsEntityList() && !data.getZhdjlGpsEntityList().isEmpty()) {
            //获取各档位参数
            DataWgjlcZhdjlgps dataWgjlcZhdjlgps = data.getZhdjlGpsEntityList().get(0);
            if(null != dataWgjlcZhdjlgps.getTestZhdjlList() && !dataWgjlcZhdjlgps.getTestZhdjlList().isEmpty()) {
                List<TestZhdjl> testZhdjlList = dataWgjlcZhdjlgps.getTestZhdjlList();
                for(int i = 0 ; i < testZhdjlList.size(); i++) {
                    params.put(testZhdjlList.get(i).getDw() + "制动距离", testZhdjlList.get(i).getZhdjlVel());
                    params.put(testZhdjlList.get(i).getDw() + "加速度", testZhdjlList.get(i).getJsdVel());
                    String dwImg = System.currentTimeMillis() + "-" + testZhdjlList.get(i).getDw() + "制动速度曲线图.png";
                    if(StringUtils.isNotEmpty(testZhdjlList.get(i).getDwSvg())) {
                        boolean res = ProcessPictureUtils.convertToPng(testZhdjlList.get(i).getDwSvg(), rootPath + data.getDataTaskEntity().getDataTaskId() + "/" + dwImg);
                        String resString = res ? "成功" : "失败";
                        System.out.println(testZhdjlList.get(0).getDw() + "制动速度曲线图导入:" + resString);
                    }
                    params.put(testZhdjlList.get(i).getDw() + "制动速度曲线图", new PictureRenderData(picSW, picSH, rootPath + data.getDataTaskEntity().getDataTaskId() + "/" +dwImg));
                }
            }
        }
        //照明和信号参数
        if(null != data.getZhmhxhEntityList() && !data.getZhmhxhEntityList().isEmpty()) {
            List<DataWgjlcZhmhxh> dataWgjlcZhmhxhList = data.getZhmhxhEntityList();
            params.put("前方20m处照明度", dataWgjlcZhmhxhList.get(0).getZhmd());
            params.put("前方是否有照明灯", dataWgjlcZhmhxhList.get(0).getHasQfzhmd().isEmpty() ? "--" : dataWgjlcZhmhxhList.get(0).getHasQfzhmd().equals("0") ? "无" : "有");
            params.put("尾部是否有照明灯", dataWgjlcZhmhxhList.get(0).getHasWbzhmd().isEmpty() ? "--" : dataWgjlcZhmhxhList.get(0).getHasWbzhmd().equals("0") ? "无" : "有");
            params.put("尾部信号灯60m处是否可见", dataWgjlcZhmhxhList.get(0).getHasWb60().isEmpty() ? "--" : dataWgjlcZhmhxhList.get(0).getHasWb60().equals("0") ? "无" : "有");
        }
        //噪声和警声参数
        if(null != data.getZshhjshEntityList() && !data.getZshhjshEntityList().isEmpty()) {
            List<DataWgjlcZshhjsh> dataWgjlcZshhjshList = data.getZshhjshEntityList();
            params.put("背景噪声", dataWgjlcZshhjshList.get(0).getBjzsh());
            params.put("头部噪声", dataWgjlcZshhjshList.get(0).getTbzsh());
            params.put("40m处噪声", dataWgjlcZshhjshList.get(0).getZsh40());
        }
        //尾气参数
        if(null != data.getWeiQiEntityList() && !data.getWeiQiEntityList().isEmpty()) {
            DataWgjlcWeiqi dataWgjlcWeiqi = data.getWeiQiEntityList().get(0);
            if(null != dataWgjlcWeiqi.getTestWeiQiList() && !dataWgjlcWeiqi.getTestWeiQiList().isEmpty()) {
                List<TestWeiQi> weiqiOneData = dataWgjlcWeiqi.getTestWeiQiList();
                for(int i = 0 ; i < weiqiOneData.size(); i++) {
                    Map<String, Object> weiqiMap = new HashMap<>();
                    weiqiMap.put("序号", i + 1);
                    weiqiMap.put("温度", weiqiOneData.get(i).getHjwd());
                    weiqiMap.put("湿度", weiqiOneData.get(i).getHjshd());
                    weiqiMap.put("大气压", weiqiOneData.get(i).getHjdqy());
                    weiqiMap.put("Co", weiqiOneData.get(i).getCo());
                    weiqiMap.put("Ch4", weiqiOneData.get(i).getCh4());
                    weiqiMap.put("NO", weiqiOneData.get(i).getNo());
                    weiqiList.add(weiqiMap);
                }
            }
        }
        //烟度参数
        if(null != data.getYanDuJiEntityList() && !data.getYanDuJiEntityList().isEmpty()) {
            DataWgjlcYanduji dataWgjlcYanduji = data.getYanDuJiEntityList().get(0);
            if(null != dataWgjlcYanduji.getTestYdList() && !dataWgjlcYanduji.getTestYdList().isEmpty()) {
                List<TestYd> yanduOneData = dataWgjlcYanduji.getTestYdList();
                for(int i = 0 ; i < yanduOneData.size(); i++) {
                    Map<String, Object> yanduMap = new HashMap<>();
                    yanduMap.put("序号", i + 1);
                    yanduMap.put("不透光值", yanduOneData.get(i).getBtgzhVel());
                    yanduMap.put("光吸收系数", yanduOneData.get(i).getGxshxshVel());
                    yanduMap.put("加热油温", yanduOneData.get(i).getJrywVel());
                    yanduList.add(yanduMap);
                }
            }
        }
        params.put("踏板力测试数据List", tblList);
        params.put("常温启动性能数据List", chwqdList);
        params.put("最大牵引力数据List", qylList);
        params.put("操纵角数据List", czjList);
        params.put("操纵力数据List", czlList);
        params.put("手刹力数据List", shshlList);
        params.put("温度保护数据List", wdbhList);
        params.put("压力保护数据List", ylbhList);
        params.put("最大静制动力数据List", zdjzdlList);
        params.put("爬坡能力数据List", ppnlList);
        params.put("尾气数据List", weiqiList);
        params.put("烟度数据List", yanduList);
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-wgjlc.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

}
